﻿// =====================================================================
// <copyright file="MemoryTraceListener.cs" author="David R. Guindo">
// 	Copyright (C) 2013. All rights reserved.
// </copyright>
// =====================================================================
// This code is released under the terms of the Apache 2.0 license, 
// http://apache.org/licenses/LICENSE-2.0.html
// =====================================================================

namespace AppBlock.Log.Test
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Security.Permissions;

    [HostProtection(SecurityAction.LinkDemand, Synchronization = true)]
    public class MemoryTraceListener : TraceListener
    {
        private static readonly Lazy<List<string>> logMemory = new Lazy<List<string>>(() => new List<string>());

        public static List<string> LogMemory
        {
            get { return logMemory.Value; }
        }

        /// <summary>
        ///     When overridden in a derived class, writes the specified message to the listener you create in the derived class.
        /// </summary>
        /// <param name="message">A message to write. </param>
        public override void Write(string message)
        {
            LogMemory.Add(message);
        }

        /// <summary>
        ///     When overridden in a derived class, writes a message to the listener you create in the derived class, followed by a
        ///     line terminator.
        /// </summary>
        /// <param name="message">A message to write. </param>
        public override void WriteLine(string message)
        {
            LogMemory.Add(message);
        }
    }
}